package com.htthorizon.auth.controller;

import com.htthorizon.common.redis.service.RedisService;
import com.sgcc.isc.core.orm.complex.FunctionTree;
import com.sgcc.isc.core.orm.identity.User;
import com.sgcc.isc.framework.common.constant.Constants;
import com.sgcc.isc.service.adapter.factory.AdapterFactory;
import com.sgcc.isc.service.adapter.helper.IIdentityService;
import com.sgcc.isc.service.adapter.impl.ResourceService;
import com.sgcc.isc.service.adapter.impl.RoleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Set;

/**
 * @author Brilliant
 */
@RestController
@Slf4j
@CrossOrigin
public class TestSSOController {

    @GetMapping("/t/getName")
    public User getName(@RequestParam("name") String name) throws Exception {
        IIdentityService service = AdapterFactory.getIdentityService();
        List<User> usersByName = service.getUsersByName(name);
        User user = usersByName.get(0);
        System.out.println(user);
        return user;
    }

    @GetMapping("/t/getTree")
    public void getTree(@RequestParam("id")String id) throws Exception {
        ResourceService service = (ResourceService) AdapterFactory.getResourceService();
        FunctionTree funcTreeByRoleId = service.getFuncTreeByRoleId(id);

        System.out.println(funcTreeByRoleId.getBusiApp());

        System.out.println(funcTreeByRoleId.getFuncNode());
    }

    @Autowired
    private RedisService redisService;

    @GetMapping("/t/t")
    public void tt(){
        Set<String> keys = redisService.redisTemplate.keys("*");
        if (!keys.isEmpty()) {
            redisService.redisTemplate.delete(keys);
        }
    }


}
